<%@ page contentType="application/javascript;charset=UTF-8" language="java" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="com.yunlu.mimas.aop.utils.ContextUtil" %>
<%@ page import="com.yunlu.mimas.aop.utils.YunluSysUser" %>
<%@ page import="com.yunlu.mercury.utilities.common.UserHelper" %>
<%@ page import="org.apache.commons.lang.StringUtils"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"></c:set>

<%
    String ct = request.getParameter("ct");
    if(StringUtils.isNotEmpty(ct) && com.yunlu.mimas.aop.utils.UserHelper.needAutoLogin(request, response)) {
        response.getWriter().write(ct + "();");
        return;
    }
    YunluSysUser user = ContextUtil.getCurrentUser();
    String callback = request.getParameter("cb");
    boolean moreInfo = request.getParameter("m") != null && request.getParameter("m").length() > 0;
    if(callback == null || callback.length() == 0) {
        callback = "callback";
    }

    callback = URLEncoder.encode(callback, "UTF-8");
    request.setAttribute("callback", callback);

    if(user != null) {
        long userId = user.getUserId();
        request.setAttribute("userid", userId);
        request.setAttribute("orgid", user.getOrgId());

        if(moreInfo) {//显示用户更多信息
            boolean isJituanUser = UserHelper.isJituanUser(userId);
            request.setAttribute("moreinfo", "{\"jituan\":" + (isJituanUser ? "true" : "false") + "}");
        }
        else {
            request.setAttribute("moreinfo", "{}");
        }
    }
%>
<c:if test="${empty SPRING_SECURITY_LAST_USERNAME}">
    ${callback}();
</c:if>
<c:if test="${not empty SPRING_SECURITY_LAST_USERNAME}">
    ${callback}('${SPRING_SECURITY_FULLNAME}', '${SPRING_SECURITY_LAST_USERNAME}', {"userid":${userid},"orgid":${orgid}}, ${moreinfo});
</c:if>